package tickets.passageRegister;


import myutil.mylist.MyArrayList;
import myutil.mylist.MyList;
import tickets.tickets.Passage;
import tickets.tickets.Ticket;
import tickets.tickets.TicketType;

/**
 *
 * @author Hlib_Babii
 */
public class PassageRegisterImpl implements PassageRegister {
    private MyList<Passage> passages = new MyArrayList<>();

    public PassageRegisterImpl() {
    }
    
    @Override
    public void addPassage(Passage passage) {
        passages.add(passage);
    }  
    
    @Override
    public MyList<Passage> getPassages() {
        return passages;
    }

    @Override
    public void setPassages(MyList<Passage> passages) {
        this.passages = passages;
    }

    @Override
    public MyList<Passage> getPassages(TicketType ticketType) {
        MyList<Passage> necessaryPassages = new MyArrayList<>();
        MyList<Passage> passages = getPassages();
        for (Passage p : passages) {
            Ticket t = p.getTicket();
            if (t != null && t.getType() == ticketType) {
                necessaryPassages.add(p);
            }
        }
        return necessaryPassages;
    }
}
